package com.sdy.hospitalguard.biz.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdy.common.model.BizException;
import com.sdy.common.utils.Assert;
import com.sdy.hospitalguard.biz.dto.ManagerDto;
import com.sdy.hospitalguard.biz.mapper.ManagerMapper;
import com.sdy.hospitalguard.biz.model.Manager;
import com.sdy.hospitalguard.biz.service.ManagerService;
import com.sdy.hospitalguard.biz.utils.CopyUtil;
import com.sdy.mvc.service.impl.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台用户表:manager 服务实现类
 * </p>
 *
 * @author zzq
 * @since 2020-05-08
 */
@Slf4j
@Service
public class ManagerServiceImpl extends BaseServiceImpl<Manager> implements ManagerService {
    @Autowired
    private ManagerMapper managerMapper;

    @Override
    public Manager getByPhone(String phone) {
        return lambdaQuery().eq(Manager::getPhone, phone).one();
    }

    @Override
    public Boolean saveOne(ManagerDto managerDto) {
        Manager manager = CopyUtil.clone(managerDto, Manager.class);
        return save(manager);
    }

    @Override
    public Boolean updStaById(Integer id, Integer state) throws BizException {
        boolean update = lambdaUpdate()
                .eq(Manager::getId, id)
                .set(Manager::getState, state == 0 ? 1 : 0)
                .update();
        Assert.notTrue(update, "修改出错!");
        return update;
    }

    @Override
    public Page pageManager(Page page, String nameAndPhone, Integer inpatientAreaId) {
        return managerMapper.pageManager(page, nameAndPhone, inpatientAreaId);
    }
}
